#include "Stdafx.h"
#include "Texture2D.h"

#include "RenderDevice.h"

namespace WindGE
{
	Texture2D::Texture2D()
		: buffer_data_(nullptr)
		, buffer_size_(0)
		, tex_(nullptr)
	{
	}

	Texture2D::~Texture2D()
	{
		release();
	}

	void Texture2D::init_desc(const D3D11_TEXTURE2D_DESC& texDesc)
	{
		tex_desc_ = texDesc;
	}

	void Texture2D::init_desc(unsigned int width, unsigned int height, DXGI_FORMAT format, 
		unsigned int miplevel /* = 0 */, unsigned int arraySize /* = 1 */, 
		unsigned int sampleCount /* = 1 */, unsigned int sampleQuality /* = 0 */, 
		D3D11_USAGE usage /* = D3D11_USAGE_DEFAULT */, 
		unsigned int bindFlag /* = D3D11_BIND_SHADER_RESOURCE */, 
		unsigned int cpuaccessFlag /* = 0 */, 
		unsigned int miscFlags /* = 0 */)
	{
		tex_desc_.Width = width;
		tex_desc_.Height = height;
		tex_desc_.Format = format;
		tex_desc_.MipLevels = miplevel;
		tex_desc_.ArraySize = arraySize;
		tex_desc_.SampleDesc.Count = sampleCount;
		tex_desc_.SampleDesc.Quality = sampleQuality;
		tex_desc_.Usage = usage;
		tex_desc_.BindFlags = bindFlag;
		tex_desc_.CPUAccessFlags = cpuaccessFlag;
		tex_desc_.MiscFlags = miscFlags;
	}

	void Texture2D::init_desc(unsigned int bindFlags, D3D11_USAGE usage, unsigned int cpuAccess, 
		DXGI_FORMAT format /* = DXGI_FORMAT_FROM_FILE */, 
		unsigned int filter /* = D3DX11_FILTER_NONE */, 
		unsigned int mipFilter /* = D3DX11_FILTER_LINEAR */)
	{
		
	}

	bool Texture2D::init_buffer(void* buffer, unsigned int sysMemPitch, unsigned int sysMemSlicePitch)
	{
		return true;
	}

	bool Texture2D::init_buffer(const void* bufferData, unsigned long bufferSize)
	{
		return true;
	}

	bool Texture2D::init_tex()
	{
		return true;
	}

	bool Texture2D::init_tex(const std::string& path)
	{
		return true;
	}

	bool Texture2D::create(ID3D11Texture2D* tex)
	{
		tex_ = tex;
		tex_->GetDesc(&tex_desc_);

		return true;
	}

	bool Texture2D::create(RenderDevicePtr renderDevice)
	{
		HRESULT hr = renderDevice->device()->CreateTexture2D(&tex_desc_, 0, &tex_);
		if (FAILED(hr)) return false;

		return true;
	}

	void Texture2D::release()
	{
		safe_release(tex_);
	}

	bool Texture2D::map(void** data, unsigned int mapType)
	{
		return true;
	}

	bool Texture2D::map(D3D11_MAPPED_SUBRESOURCE* pResource, 
		unsigned int subResource, D3D11_MAP maptype, unsigned int mapflags)
	{
		return true;
	}

	void Texture2D::unmap(unsigned int subResource /* = 0 */)
	{

	}

}//end namespace WindGE


